import 'package:flutter/material.dart';
import 'package:whale/pages/home/subs/tab_sub/index.dart';

///处理标题列表页面下多个重复字页面是，控制器复用，造成数据混乱的问题
class TabContainerPage extends StatefulWidget {
  const TabContainerPage({super.key});

  @override
  State<TabContainerPage> createState() => _TabContainerPageState();
}

class _TabContainerPageState extends State<TabContainerPage>
    with SingleTickerProviderStateMixin {
  late TabController tabCtrl;
  late final List<String> titles = ['热门', '推荐', '天选'];

  @override
  void initState() {
    tabCtrl = TabController(length: titles.length, vsync: this);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        TabBar(
            controller: tabCtrl,
            tabs: List.generate(titles.length, (e) {
              return Tab(
                text: titles[e],
              );
            })),
        Expanded(
            child: TabBarView(
                controller: tabCtrl,
                children: List.generate(titles.length, (e) {
                  return TabSubPage(
                    tag: e,
                  );
                })))
      ],
    );
  }
}
